<?php
$sub_menu = "230200";
include_once("./_common.php");

auth_check($auth[$sub_menu], "w");

$token = get_token();

$g4[title] = $html_title;
include_once("$g4[admin_path]/admin.head.php");

$html_title = $mw_cash[cf_cash_name];
if ($w == "") 
{
    $html_title .= " 등록";
    $attr = "";

    $row = array();
    $row[cl_tax_voucher] = "''";
    $row[cl_voucher] = "''";
    if ($mb_id)
        $row[mb_id] = $mb_id;
} 
else if ($w == "u") 
{
    $html_title .= " 수정";
    $row = sql_fetch("select * from $mw_cash[cash_list_table] where cl_id = '$cl_id'");

    $attr = "readonly style='background-color:#efefef'";
} 
else
    alert("제대로 된 값이 넘어오지 않았습니다.");

preg_match("/\[LGD_CARDINSTALLMONTH\] => ([0-9]+)?/i", $row['cl_paylog'], $match); 
$card_install_month = (int)$match[1];

if ($card_install_month) {
    preg_match("/\[LGD_CARDNOINTYN\] => ([0-9]+)?/i", $row['cl_paylog'], $match); 
    if ((int)$match[1])
        $card_nointyn = "무이자";
    else
        $card_nointyn = "유이자";
}
?>

<form name=fwrite method=post action="mw.cash.update.php" autocomplete="off">
<input type=hidden name=w     value='<?=$w?>'>
<input type=hidden name=sfl   value='<?=$sfl?>'>
<input type=hidden name=stx   value='<?=$stx?>'>
<input type=hidden name=sst   value='<?=$sst?>'>
<input type=hidden name=sod   value='<?=$sod?>'>
<input type=hidden name=page  value='<?=$page?>'>
<input type=hidden name=token value='<?=$token?>'>
<input type=hidden name=cl_id value='<?=$cl_id?>'>
<input type=hidden name=fr_date value="<?=$fr_date?>">
<input type=hidden name=to_date value="<?=$to_date?>">
<input type=hidden name=date value="<?=$date?>">
<input type=hidden name=acc value="<?=$acc?>">

<table width=100% cellpadding=0 cellspacing=0>
<colgroup width=30% class='col1 pad1 bold right'>
<colgroup width=70% class='col2 pad2'>
<tr class='ht'>
    <td colspan=4 class=title align=left><img src='<?=$g4[admin_path]?>/img/icon_title.gif'> <?=$html_title?></td>
</tr>
<tr><td colspan=4 class='line1'></td></tr>
<? if ($w != "") { ?>
<tr class='ht'>
    <td width=30% class='col1 pad1 bold right'>주문번호</td>
    <td>
	C<?=$row[cl_id]?>
    </td>
</tr>
<? } ?>
<tr class='ht'>
    <td class='col1 pad1 bold right'>회원ID</td>
    <td>
	<? if ($w == "") { ?>
	<input type="text" size="15" name="mb_id" class="ed" required itemname="회원ID" value="<?=$row[mb_id]?>">
	<? } else { ?>
	<a href="mw.cash.list.php?sfl=mb_id&stx=<?=$row[mb_id]?>"><?=$row[mb_id]?></a>
	<? } ?>
    </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'><?=$mw_cash[cf_cash_name]?></td>
    <td>
	<? if ($w == "") { ?>
	<input type="text" size="15" name="cl_cash" class="ed" required itemname="<?=$mw_cash[cf_cash_name]?>" value="<?=$row[cl_cash]?>" <?=$attr?>>
	<? } else echo number_format($row[cl_cash]); ?>
	<?=$mw_cash[cf_cash_unit]?>
	<? if ($w == "") $row[cl_cash_price] = $mw_cash[cf_cash_price] ?>
	<span style="color:#aaa; font-size:11px; font-family:gulim;">
        <? if ($row[cl_paytype] == "페이팔") { ?>
	(결제시점의 <?=$mw_cash[cf_cash_name]?> 단가 : <?=number_format($row[cl_cash_price], 2)?> $)
        <? } else { ?>
	(결제시점의 <?=$mw_cash[cf_cash_name]?> 단가 : <?=number_format($row[cl_cash_price])?>원<? if ($row[cl_tax]) echo ", 부가세별도"; ?>)
        <? } ?> 
	</span>
    </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>결제방법</td>
    <td>
	<? if ($w == "") { ?>
	<select name="cl_paytype" itemname="결제방법">
	<option value=""></option>
	<option value="포인트">포인트</option>
	<option value="무통장입금">무통장입금</option>
	<option value="신용카드">신용카드</option>
	<option value="핸드폰">핸드폰</option>
	<option value="계좌이체">실시간계좌이체</option>
	<option value="페이팔">페이팔</option>
	<option value="서비스">서비스</option>
	</select>
	<? } else echo $row[cl_paytype]; ?>
    </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>결제 금액 (포인트)</td>
    <td>
	<? if ($w == "") { ?>
	<input type="text" size="15" name="cl_payment" class="ed" itemname="결제금액" value="<?=$row[cl_payment]?>">
	<? }
        else if ($row[cl_paytype] == "페이팔")  echo number_format($row[cl_payment], 2) . " $";
        else if ($row[cl_paytype] == "포인트")  echo number_format($row[cl_payment]) . " 점";
        else  echo number_format($row[cl_payment]). " 원";
        if ($card_install_month)
            echo " ({$card_nointyn} 할부 {$card_install_month}개월)";
        else if ($w == "u")
            echo " (일시불)";
        ?>
    </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>내용</td>
    <td>
	<? //if ($w == "") { ?>
	<input type="text" size="80" name="cl_content" class="ed" itemname="내용" value="<?=$row[cl_content]?>" <?//=$attr?>>
	<? //} else echo $row[cl_content]; ?>
    </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>사용도메인</td>
    <td>
	<input type="text" size="80" name="cl_domain" class="ed" itemname="사용도메인" value="<?=$row[cl_domain]?>">
    </td>
</tr>
<? if ($w == "u") { ?>
<tr class='ht'>
    <td class='col1 pad1 bold right'>일시</td>
    <td> <?=$row[cl_datetime]?> </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>IP</td>
    <td> <?=$row[cl_ip]?> </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>AGENT</td>
    <td> <div title="<?=$row[cl_agent]?>"><?=cut_str($row[cl_agent], 80)?></div> </td>
</tr>
<? } ?> 
<tr class='ht'>
    <td class='col1 pad1 bold right'>관련테이블</td>
    <td>
	TABLE : <input type="text" size="20" name="rel_table" class="ed" value="<?=$row[rel_table]?>">
	ID : <input type="text" size="10" name="rel_id" class="ed" value="<?=$row[rel_id]?>">
    </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>결제 log</td>
    <td>
    <? if ($attr) $attr = str_replace("style='", "style='width:100%; height:100px; ", $attr); ?>
    <textarea name="cl_paylog" class="ed" itemname="결제log" <?=$attr?> style="width:100%; height:100px;"><?=$row[cl_paylog]?></textarea> </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>관리자 메모</td>
    <td> <textarea style="width:100%; height:100px;" name="cl_admin_memo" class="ed" itemname="관리자메모"><?=$row[cl_admin_memo]?></textarea> </td>
</tr>
<tr class='ht'>
    <td class='col1 pad1 bold right'>세금</td>
    <td>
	<input type="checkbox" name="cl_tax_voucher" value="1"> 세금계산서 발행 
	<input type="checkbox" name="cl_voucher" value="1"> 현금영수증 발행
	<script type="text/javascript">
	fwrite.cl_tax_voucher.checked = <?=$row[cl_tax_voucher]?>;
	fwrite.cl_voucher.checked = <?=$row[cl_voucher]?>;
	</script>
    </td>
</tr>
<tr><td colspan=4 class='line2'></td></tr>
</table>

<p align=center>
    <input type=submit class=btn1 accesskey='s' value='  확  인  '>&nbsp;
    <input type=button class=btn1 value='  목  록  ' onclick="document.location.href='mw.cash.list.php?<?=$qstr?>';">
</form>

<?
include_once ("$g4[admin_path]/admin.tail.php");
